package app.form;

import app.form.component.IComponent;
import app.form.component.Radio;
import app.form.component.Select;
import app.form.component.Text;
import java.util.ArrayList;
import java.util.List;

public class Form implements IComponent {
    private List<IComponent> listComponents;
    public static List<Float> getXValues () {
        List<Float> v = new ArrayList<Float>();
        for (int i = -3; i <= 5; ++ i) {
            v.add (new Float(i));
        }
        return v;
    }
    public static Float getYMin () {
        return new Float(-3);
    }
    public static Float getYMax () {
        return new Float(3);
    }
    public static List<Float> getRValues () {
        List<Float> v = new ArrayList<Float>();
        for (float x = 1; x <= 3; x += 0.5) {
            v.add(new Float(x));
        }
        return v;
    }
    public Form() { 
        listComponents = new ArrayList<IComponent>();
        listComponents.add(new Select("x", "X:", getXValues()));
        listComponents.add(new Text("y", "Y:", getYMin(), getYMax()));
        listComponents.add(new Radio("r", "R:", getRValues()));
    }
    @Override
    public String renderHTML() {
        StringBuilder s = new StringBuilder();
        s.append("<p>Выберите точку</p>\r\n");
        for (IComponent cmp : listComponents) {
            s.append(cmp.renderHTML() + "\r\n");
        }
        s.append("<div class='btn_send' onClick='JavaScript: sendForm();'><button>Отправить</button></div>");
        return s.toString();
    }
    @Override
    public String renderJS() {
        StringBuilder s = new StringBuilder();
        for (IComponent cmp : listComponents) {
            s.append(cmp.renderJS() + "\r\n");
        }
        return s.toString();
    }
    @Override
    public String renderCSS() {
        StringBuilder s = new StringBuilder();
        for (IComponent cmp : listComponents) {
            s.append(cmp.renderCSS() + "\r\n");
        }
        s.append(".title{"
                    + "float: left;"
                    + "display: block;"
                    + "width: 30px;"
                + "}\r\n"
                + ".btn_send{"
                    + "padding-top: 10px;"
                + "}");
        return s.toString();
    }
}
